﻿@model Tuple<IList<Web.Entities.Inflection>, IEnumerable<SelectListItem>>

@{
    ViewBag.Title = "Inflector";
}
<style>
TD
{
	padding-left: 3em;
}
.removeInflection
{
	color: #FF0000
}
</style>


<h2>Таблица склонений</h2>
<br />
<a href="#" class="showLightBox_link" rel="addInflectionBox">Добавить склонение</a> <br />
<a href="#" class="showLightBox_link" rel="addInflectionYandexBox">Добавить склонение, используя Яндекс.Склонятор</a>
<table id="inflectionTable" rel="@Url.Action("Delete", "Inflection")">
<thead>
	<tr>
		<td>Normal form</td>
		<td>Singular</td>
		<td>Case</td>
		<td>Result form</td>
		<td></td>
	</tr>
</thead>
<tbody>
@foreach (var inflection in Model.Item1)
{
	<tr rel="@inflection.Id">
		<td>@inflection.NormalForm</td>
		<td>@inflection.Singular</td>
		<td>@inflection.Case</td>
		<td>@inflection.ResultForm</td>
		<td><a href="#" class="removeInflection" rel="@inflection.Id">Удалить</a></td>
	</tr>
}
</tbody>
</table>

<script type="text/javascript">

	$(document).ready(function () {

		$('.removeInflection').click(function () {
			var actionMethodUrl = $('#inflectionTable').attr('rel');
			var inflectionId = $(this).attr('rel');
			var data = "id=" + inflectionId;
			var successFunc = $(this)[0].success || baseSuccess;
			$.ajax({
				'url': actionMethodUrl,
				'type': 'POST',
				//'dataType': 'json',
				'data': data,
				'success': successFunc,
				'error': function (jqXHR, textStatus, errorThrown) {
					alert(jqXHR + ', ' + textStatus + ', ' + errorThrown);
				},
				'beforeSubmit': function () {
					//показываем крутилку
				},
				'complete': function () {
					//скрыть крутилку
				}
			});

			var rootListItem = $(this).closest('tbody');
			var children = rootListItem.children('tr');
			jQuery.each(children, function () {
				if ($(this).attr('rel') == inflectionId)
					$(this).hide();
			});
		});
	});
</script>

<div id="lightbox_shadow">&nbsp;</div>
<div class="lightbox" id="addInflectionBox">
    <a href="#" class="lightbox_close">Закрыть</a>	
 @using (Html.BeginForm("Create", "Inflection", FormMethod.Post, new { @class = "ajaxForm" }))
 {
	<fieldset>
		@Html.Label("Начальная форма")
		@Html.TextBox("NormalForm")
		<br />
		
		@Html.Label("Единственное число")
		@Html.CheckBox("Singular")
		<br />

		@Html.Label("Падеж")
		@Html.DropDownList("Case", Model.Item2)
		<br />

		@Html.Label("Изменённая форма")
		@Html.TextBox("ResultForm")
		<br />
	</fieldset>
	@Html.SubmitButton(null, "Сохранить")
}
</div>

<div class="lightbox" id="addInflectionYandexBox">
    <a href="#" class="lightbox_close">Закрыть</a>	
 @using (Html.BeginForm("CreateUsingYandex", "Inflection", FormMethod.Post, new { @class = "ajaxForm" }))
 {
	<fieldset>
		@Html.Label("Начальная форма")
		@Html.TextBox("NormalForm")
		<br />
		
		@Html.Label("Единственное число")
		@Html.CheckBox("Singular")
		<br />

		@Html.Label("Падеж")
		@Html.DropDownList("Case", Model.Item2)
		<br />
	</fieldset>
	@Html.SubmitButton(null, "Сохранить")
}
</div>